<?php
use yii\helpers\Url;
?>
部门列表页
<?php
    var_dump($departmentsList);
?>
上级部门：<select id="upperDepart">
    <?php foreach($departmentsList as $key=>$value){ ?>
            <option value="<?=$value['id']?>"><?=$value['departName'] ?></option>
    <?php } ?>
            </select>
<br>

部门名称：<input id="departName" type="text" value="" placeholder="请填写部门名称">

<input type="button" value="新增部门" onclick="addDepartment()">
<script>
    function addDepartment(){
        var params={};
        params.parentId=$('#upperDepart').val();
        params.departName=$('#departName').val();
        var url='<?=Url::toRoute(['system/add-departmented'])?>';
        $.post(url,params,function(data){
            var data=JSON.parse($data);
            if(data.errcode==0){
                alert(data.errmsg);
                window.location.reload();
            }else{
                alert(data.errmsg);
            }
        });
    }
</script>
